home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / examples / misc / xpcolor.pro < prev   
Text File  |  1997-07-08  |  3KB  |  115 lines

  1. ; $Id: xpcolor.pro,v 1.4 1997/01/15 04:21:02 ali Exp $
  2. ;
  3. ; Copyright (c) 1993-1997, Research Systems, Inc.  All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5. ;+
  6. ; NAME:
  7. ;       XPCOLOR
  8. ;
  9. ; PURPOSE:
  10. ;    The primary purpose of this routine is to serve as an example for
  11. ;    the Widgets chapter of the IDL User's Guide.
  12. ;
  13. ;    XPCOLOR allows the user to adjust the value of the current foreground
  14. ;    plotting color, !P.COLOR. For a more flexible color editor,
  15. ;    try the XPALETTE User Library Procedure.
  16. ;
  17. ; CATEGORY:
  18. ;       Color tables, widgets.
  19. ;
  20. ; CALLING SEQUENCE:
  21. ;       XPCOLOR
  22. ;
  23. ; INPUTS:
  24. ;       No explicit inputs.  The current color table and the value of !P.COLOR
  25. ;    are used.
  26. ;
  27. ; KEYWORD PARAMETERS:
  28. ;       GROUP - Group leader, as passed to XMANAGER.
  29. ;
  30. ; OUTPUTS:
  31. ;       None.
  32. ;
  33. ; COMMON BLOCKS:
  34. ;       COLORS: Contains the current RGB color tables.
  35. ;
  36. ; SIDE EFFECTS:
  37. ;       The new plotting foreground color is saved in the COLORS common
  38. ;    and loaded to the display.
  39. ;
  40. ; PROCEDURE:
  41. ;       Three sliders (R, G, and B) allow the user to modify the 
  42. ;       current color.
  43. ;
  44. ; MODIFICATION HISTORY:
  45. ;    20 October 1993, AB, RSI
  46. ;-
  47.  
  48. PRO xpcolor_event, ev
  49.  
  50.   COMMON colors, r_orig, g_orig, b_orig, r_curr, g_curr, b_curr
  51.  
  52.   WIDGET_CONTROL, GET_UVALUE=type, ev.id
  53.   IF (type EQ 0) THEN BEGIN
  54.     IF (ev.value EQ 0) THEN WIDGET_CONTROL, /DESTROY, ev.top $
  55.     ELSE XDISPLAYFILE,TITLE='XPcolor Help',GROUP=ev.top, HEIGHT=10,WIDTH=60, $
  56.     TEXT = ['This is the XPCOLOR demo program which appears in.', $
  57.         'the IDL User''s Guide near the end of the Widgets Chapter', $
  58.                 '', 'It allows you to change the plotting color used by IDL', $
  59.             'by using the sliders at the bottom of the control panel.', $
  60.                 'When you''re finished, press the "Done" button', $
  61.         '', 'For a more full featured color editor, try XPALETTE' ]
  62.   ENDIF ELSE BEGIN
  63.     r_curr[!P.COLOR] = ev.r
  64.     g_curr[!P.COLOR] = ev.g
  65.     b_curr[!P.COLOR] = ev.b
  66.     TVLCT, ev.r, ev.g, ev.b, !P.COLOR
  67.   ENDELSE
  68.  
  69. END
  70.  
  71.  
  72.  
  73.  
  74. pro xpcolor,GROUP=group
  75.  
  76.   common colors, r_orig, g_orig, b_orig, r_curr, g_curr, b_curr
  77.  
  78.   ; Ensure we have a window to establish colors.
  79.   save = !D.WINDOW
  80.   IF (save EQ -1) THEN BEGIN
  81.     WINDOW,/PIXMAP,/FREE,XSIZE=2,YSIZE=2
  82.     ; Can free it right away. 
  83.     WDELETE,!D.WINDOW
  84.   ENDIF
  85.  
  86.    IF N_ELEMENTS(r_orig) LE 0 THEN BEGIN ;If no common, use current colors
  87.      TVLCT, r_orig, g_orig, b_orig, /GET
  88.      r_curr = r_orig
  89.      b_curr = b_orig
  90.      g_curr = g_orig
  91.    ENDIF
  92.  
  93.   base = WIDGET_BASE(/COLUMN, title='Set Plot Color')
  94.  
  95.   ; Setting the managed attribute indicates our intention to put this app
  96.   ; under the control of XMANAGER, and prevents our draw widgets from
  97.   ; becoming candidates for becoming the default window on WSET, -1. XMANAGER
  98.   ; sets this, but doing it here prevents our own WSETs at startup from
  99.   ; having that problem.
  100.   WIDGET_CONTROL, /MANAGED, base
  101.  
  102.   b = CW_BGROUP(base, /ROW, ['Done', 'Help'], UVALUE=0)
  103.   draw = WIDGET_DRAW(base, XSIZE=100, YSIZE=50)
  104.   rgb = CW_RGBSLIDER(base, /DRAG, UVALUE=1)
  105.   WIDGET_CONTROL, rgb, SET_VALUE=[r_curr[!P.color], g_curr[!P.color], $
  106.     b_curr[!P.color] ]
  107.   widget_control,/real,base
  108.   WIDGET_CONTROL, draw, GET_VALUE=win_id
  109.  
  110.   WSET, win_id
  111.   ERASE, color=!P.COLOR
  112.   WSET, save
  113.   XMANAGER, 'XPCOLOR', base, GROUP=group, /NO_BLOCK
  114. end
  115.